<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #MyMap {
            width: 100%;
            height: 300px;
        }
    </style>
</head>
<body>
<div id="MyMap"></div>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=3ogrcWyULvn8nx1HnOQRoD6m"></script>
<script>
//http://developer.baidu.com/map/jsdemo.htm#a5_2
/*
财富广场

 latitude
 :
 31.880964
 longitude
 :
 117.266015
 */


    navigator.geolocation.getCurrentPosition(function(position){
        console.log(position);
        var x = position.coords.longitude; //经

        var y = position.coords.latitude;//纬

        var ggPoint = new BMap.Point(x,y);
        console.log(ggPoint);
        var map = new BMap.Map('MyMap');
        map.centerAndZoom(ggPoint,18);
        map.addControl(new BMap.MapTypeControl());   //添加地图类型控件
        var mk =new  BMap.Marker(ggPoint);
        map.addOverlay(mk);
        map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
        //坐标转换完之后的回调函数
        translateCallback = function (data){
            if(data.status === 0) {
                var marker = new BMap.Marker(data.points[0]);
                map.addOverlay(marker);
                var label = new BMap.Label("转换后的百度坐标（正确）",{offset:new BMap.Size(20,-10)});
                marker.setLabel(label); //添加百度label
                map.setCenter(data.points[0]);
            }
        }

        setTimeout(function(){
            var convertor = new BMap.Convertor();
            var pointArr = [];
            pointArr.push(ggPoint);
            convertor.translate(pointArr, 1, 5, translateCallback)
        }, 1000);
    },function (error) {
        console.log(error);
    })


</script>
</body>
</html>